<?php
/**
 * Created by PhpStorm.
 * User: mww
 * Date: 2018/12/17
 * Time: 16:08
 */
namespace app\api\controller;
use think\Db;
class Homeps extends Base
{
    /**
     * 异地登录验证
     * @return string|void
     */
    public function _initialize()
    {
        extract(input());
        if($user_id != 0){
            $auth = $this->checkAll($user_id,$time,$value,$reqKey);
            if($auth == 112){
                echo json_encode(['status'=>301,'msg'=>$this->otherLogin]);
                exit;
            }elseif($auth == 110){
                echo json_encode(['status' => 302, 'msg' => $this->frost]);
                exit;
            }elseif($auth == 1103){
                echo json_encode(['status' => 303, 'msg' => $this->del]);
                exit;
            }
        }

    }

    /**
     * 我关联了几个学生
     *
     */
    public function myWanshan(){
        extract(input());
        $data = Db::table('up_u_user_son')->alias('us')
//            ->join('up_area a','us.uson_shi=a.district_id','LEFT')
            ->join('up_school s','us.uson_school=s.school_id','LEFT')
            ->where('uson_user_id',$user_id)
            ->where('uson_status',1)
            ->field('us.*,school_name_remark school_name,uson_grade grade_name')
            ->select();
        return json(['status'=>200,'msg'=>$data]);

    }
    /**
     * 给在线客服用的，查找学校编码
     */
    public function getUserSchoolCodes(){
        extract(input());
        $data = Db::table('up_u_user_son')->alias('us')
            ->join('up_school s','us.uson_school=s.school_id','LEFT')
            ->where('uson_user_id',$user_id)
            ->where('uson_status',1)
            ->column('school_erp');
        $codes = '';
        if($data) $codes = implode(',',$data);
        return json(['status'=>200,'msg'=>$codes]);

    }
    /**
     * 用户注销（上架用）
     */
    public function zhuxiao(){
        extract(input());
        $logs = Db::table('up_u_user')->where('user_id', $user_id)->value('user_dj_log');
        if($logs){
            $logs .= '|用户自己' . '于' . date('Y-m-d H:i:s') . '冻结';
        }else{
            $logs = '用户自己于' . date('Y-m-d H:i:s') . '冻结';
        }
        $update = [
            'user_status' => 2,
            'user_dj_log' => $logs
        ];
        Db::table('up_u_user')
            ->where('user_id',$user_id)
            ->update($update);
        return json(['status'=>200,'msg'=>'操作成功']);

    }
    /**
     * 删除学生
     *
     */
    public function delSon(){
        extract(input());
        $data = Db::table('up_u_user_son')->where('uson_id',$uson_id)->value('uson_num');
        if($data){
            Db::table('up_school_number')->where('sn_number',$data)->update([
                'sn_uson_id' => '',
                'sn_status' => 1
            ]);
        }
        Db::table('up_u_user_son')
            ->where('uson_id',$uson_id)
            ->update([
                'uson_status' => 2,
                'uson_num' => '',
            ]);
        $sonid = Db::table('up_u_user')->where('user_id',$user_id)->value('user_son_id');
        if($sonid && $sonid == $uson_id) Db::table('up_u_user')->where('user_id',$user_id)->setField('user_son_id',0);
        return json(['status'=>200,'msg'=>'操作成功']);

    }
    /**
     * 关联后选择
     *
     */
    public function afterWanshan(){
        extract(input());
        $update = [
            'user_son_id' => $uson_id,
            'user_update_time' => date('Y-m-d H:i:s')
        ];
        $data = Db::table('up_u_user_son')->where('uson_id',$uson_id)
            ->field('user_gender,uson_year,uson_school,uson_idcard')
            ->find();
        if (empty($data['uson_year']) || $data['uson_year'] <= 2000) {
            return json(['status' => 0, 'msg' => '识别到学生的入学年份不存在,请先去编辑完善']);
        }
        if (empty($data['user_gender'])) {
            return json(['status' => 0, 'msg' => '识别到学生的性别没有填写,请先去编辑完善']);
        }
        if (empty($data['uson_school'])) {
            return json(['status' => 0, 'msg' => '识别到学生的学校没有选择,请先去编辑完善']);
        }
//        if (empty($data['uson_idcard'])) {
//            return json(['status' => 0, 'msg' => '识别到学生的身份证号不存在,请先去编辑完善']);
//        }

        $res = Db::table('up_u_user')
            ->where('user_id',$user_id)
            ->update($update);
        if($res){
            return json(['status'=>200,'msg'=>'ok']);
        }else{
            return json(['status'=>0,'msg'=>'操作失败，请刷新重试']);
        }

    }
    /**
     * 获取学校和年级
     */
    public function getSchoolGrade()
    {
        extract(input());
//        $school = Db::table('up_school')
//            ->where('school_status',1)
//            ->field('school_id,school_erp,school_name')
//            ->select();
        $grade = Db::table('up_grade')->field('grade_id,grade_name')->select();
        $now_y = date('Y');
        $year = [
            $now_y,
            $now_y-1,
            $now_y-2,
            $now_y-3,
            $now_y-4,
            $now_y-5,
            $now_y-6
        ];
        $school = [];
        if(isset($keyword) && $keyword){
            $newkey1 = mb_substr($keyword,0,1);
            $newkey2 = mb_substr($keyword,0,2);
            if($newkey2 == '南京') $keyword = str_replace('南京','',$keyword);
            if($newkey1 == '市') $keyword = str_replace('市','',$keyword);
            if(mb_strlen($keyword) >= 2){
                $school = Db::table('up_school')->alias('s')
                    ->join('up_school_number sn','s.school_id=sn.sn_school_id','LEFT')
                    ->where('school_status',1)
                    ->where('school_name|school_name_remark','like','%'.$keyword.'%')
                    ->group('school_id')
                    ->field('school_id,school_erp,school_name_remark school_name,sn_id')
                    ->select();
            }
//            $keyword = strtoupper($keyword);
//            $school = Db::table('up_school')
//                ->where('school_status',1)
//                ->where('school_erp_num',$keyword)
//                ->field('school_id,school_erp,school_name')
//                ->select();
        }
        return json(['status'=>200,'msg'=>$school,'grade'=>$grade,'year'=>$year]);
    }
    /**
     * 获取学校对应年级
     */
    public function getSchoolUnderGrade()
    {
        extract(input());
        $grade = Db::table('up_school_grade')
            ->where('grade_school_erp',$school_erp)
            ->field('grade_id,grade_name')
            ->order('grade_level')
            ->select();
        return json(['status'=>200,'msg'=>$grade]);
    }
    /**
     * 获取学校对应年级
     */
    public function gradeRight($school_id,$gradeid,$year)
    {
        extract(input());
        $now = date('Y');
        $now2 = date('Y-m-d');
        $school_erp = Db::table('up_school')->where('school_id',$school_id)->value('school_erp');
        $grades = Db::table('up_school_grade')
            ->where('grade_school_erp',$school_erp)
            ->field('grade_id,grade_name')
            ->order('grade_level')
            ->select();
        $cha = $now - $year;
        if($cha <= 0){
            $cha = 1;
        }else{
            if($now2 >= $now . '-08-01'){
                $cha = $cha+1;
            }
        }
        if($cha > count($grades)) return ['status' => 0 , 'msg' => '入学年份选择错误！'];
        if($grades[$cha-1]['grade_id'] == $gradeid){
            return ['status' => 200];
        }else{
            return ['status' => 0 , 'msg' => '此入学年份应选择' . $grades[$cha-1]['grade_name']];
        }
    }

    /**
     * 完善资料
     *
     */
    public function addNewWanshan()
    {
        extract(input());
        $today = date('Y-m-d H:i:s');
        if (empty($uson_username)) {
            return json(['status' => 1, 'msg' => '名字不能为空']);
        }
        if (!preg_match("/^1[123456789]\d{9}$/", $uson_parent_phone)) {
            return json(['status' => 1, 'msg' => '请填写正确的手机号码']);
        }
//        $hkcard = Db::table('up_u_user_hkphone')->column('card');
//        if(!in_array($uson_idcard,$hkcard)) {
//            if ($this->is_idcard($uson_idcard)) {
//                $age = date('Y') - substr($uson_idcard, 6, 4) - (date('md') >= substr($uson_idcard, 10, 4) ? 0 : 1);
//                if ($age < 5 || $age > 20) {
//                    return json(['status' => 1, 'msg' => '年龄不得低于5岁且不能高于20岁，请核实学生身份证号']);
//                }
//                $sexint = (int)substr($uson_idcard, 16, 1);
//                $sexint = $sexint % 2 === 0 ? '2' : '1';
//                if ($sexint != $user_gender) {
//                    return json(['status' => 1, 'msg' => '您选择的性别与身份证号性别不一致']);
//                }
//            } else {
//                return json(['status' => 1, 'msg' => '请输入正确的身份证号']);
//            }
//        }
//        if (!$uson_sheng || !$uson_shi || !$uson_qu || !$uson_address) {
//            return json(['status' => 1, 'msg' => '地址不能为空']);
//        }
        if (empty($uson_school)) {
            return json(['status' => 1, 'msg' => '学校不能为空']);
        }
        if (empty($uson_year)) {
            return json(['status' => 1, 'msg' => '入学年份不能为空']);
        }
        if (empty($uson_grade)) {
            return json(['status' => 1, 'msg' => '年级不能为空']);
        }
        if (!isset($uson_height)) $uson_height = '';
        if (!isset($uson_weight)) $uson_weight = '';
        //////---------------------------------------------------------------------
        $right = $this->gradeRight($uson_school,$uson_grade,$uson_year);
        if($right['status'] != 200){
            return json($right);
        }
        //////---------------------------------------------------------------------
        $gradename = Db::table('up_school_grade')
            ->where('grade_id', $uson_grade)
            ->value('grade_name');
        $data = [
            'uson_user_id' => $user_id,
            'uson_username' => $uson_username,
//            'uson_idcard' => $uson_idcard,
            'uson_parent_phone' => $uson_parent_phone,
            'user_gender' => $user_gender,
            'uson_year' => $uson_year,
            'uson_school' => $uson_school,
            'uson_grade_id' => $uson_grade,
            'uson_grade' => $gradename,
            'uson_class' => $uson_class,
            'uson_size' => $uson_size,
//            'uson_sheng' => $uson_sheng,
//            'uson_shi' => $uson_shi,
//            'uson_qu' => $uson_qu,
//            'uson_address' => $uson_address,
            'uson_height' => $uson_height,
            'uson_weight' => $uson_weight,
            'uson_time' => $today,
            'uson_update_time' => $today
        ];
//        $have = Db::table('up_u_user_son')
//            ->where('uson_idcard', $uson_idcard)
//            ->where('uson_status', '<>', 3)
//            ->find();
//        if ($have) {
//            return json(['status' => 0, 'msg' => '已经有此身份证号了']);
//        } else {
            Db::startTrans();
            try {
                if(isset($sun_num) && $sun_num){
                    $haveNum = Db::table('up_school_number')->where('sn_number',$sun_num)->find();
                    if(!$haveNum) return json(['status' => 1, 'msg' => '学号填写错误！']);
                    if($haveNum['sn_status'] != 1 || $haveNum['sn_uson_id']) return json(['status' => 1, 'msg' => '学号已被绑定！']);
                    //
                    $data['uson_num'] = $sun_num;
                    $res = Db::table('up_u_user_son')->insertGetId($data);
                    Db::table('up_school_number')->where('sn_number',$sun_num)->update([
                        'sn_uson_id' => $res,
                        'sn_status' => 2,
                        'sn_bindtime' => $today
                    ]);
                }else{
                    $res = Db::table('up_u_user_son')->insertGetId($data);
                }
                //---------------------------------------------------------------------------
                $wanshan = Db::table('up_u_user')->where('user_id',$user_id)
                    ->field('user_old,user_son_id')->find();
                if(empty($wanshan['user_son_id'])){
                    Db::table('up_u_user')->where('user_id',$user_id)->setField('user_son_id',$res);
                }
                if($wanshan['user_old'] == 2){
                    $user_phone = Db::table('up_u_user')->where('user_id', $user_id)->value('user_phone');
                    Db::table('up_z_old_order_detail')
                        ->where('old_phone', $user_phone)
                        ->where('old_stu_name', $uson_username)
                        ->setField('detail_user_son_id', $res);
                    $old = Db::table('up_z_old_order_detail')
                        ->where('old_phone', $user_phone)
                        ->where('old_stu_name', $uson_username)
                        ->group('order_id')
                        ->column('order_id');
                    //
                    Db::table('up_z_old_order')
                        ->where('order_id', 'in', $old)
                        ->update([
                            'user_id' => $user_id,
                            'order_user_son_id' => $res,
                        ]);
                    $orders = Db::table('up_z_old_order')
                        ->where('order_id', 'in', $old)
                        ->field('old_phone', true)
                        ->select();
                    foreach ($orders as $k => $v) {
                        $old_oid = $v['order_id'];
                        unset($v['order_id']);
                        $oid = Db::table('up_self_order')->insertGetId($v);
                        Db::table('up_z_old_order_detail')
                            ->where('order_id', $old_oid)
//                            ->where('old_phone', $user_phone)
//                            ->where('old_stu_name', $uson_username)
                            ->setField('order_id', $oid);
                        $details = Db::table('up_z_old_order_detail')
                            ->where('order_id', $oid)
                            ->field('detail_id,old_phone,old_stu_name', true)
                            ->select();
                        Db::table('up_self_order_detail')->insertAll($details);
                    }
                }
                //---------------------------------------------------------------------------
                //同时同步到我的地址
//                $address = [
//                    'address_name' => $uson_username,
//                    'address_phone' => $uson_parent_phone,
//                    'address_sheng' => $uson_sheng,
//                    'address_shi' => $uson_shi,
//                    'address_qu' => $uson_qu,
//                    'address_detail' => $uson_address,
//                    'address_time' => $today,
//                    'address_update_time' => $today,
//                    'address_default' => 2,
//                    'address_user_id' => $user_id,
//                    'address_uson_id' => $res,
//                ];
//                Db::table('up_my_address')->insert($address);
                Db::commit();
                return json(['status'=>200,'msg'=>'添加成功']);
            } catch (\Exception $e) {
                Db::rollback();
                return json(['status'=>100,'msg'=>'添加失败，请刷新重试']);
            }
//        }
    }

    /**
     * 获取学生信息
     * @return \think\response\Json
     */
    public function getStuInfo()
    {
        $uson_id = $_POST['uson_id'];
        $data = Db::table('up_u_user_son us')
            ->join('up_school s','us.uson_school=s.school_id','LEFT')
            ->join('up_area a','us.uson_sheng=a.district_id','LEFT')
            ->join('up_area aa','us.uson_shi=aa.district_id','LEFT')
            ->join('up_area aaa','us.uson_qu=aaa.district_id','LEFT')
            ->where('uson_id',$uson_id)
            ->field('us.*,s.school_id,s.school_name_remark school_name,s.school_erp,a.district sheng,aa.district shi,aaa.district qu')
            ->find();
        $data['sn_id'] = '';
        $have = Db::table('up_school_number')->where('sn_school_id',$data['school_id'])->value('sn_id');
        if($have) $data['sn_id'] = $have;
        return json(['status'=>200,'msg'=>$data]);
    }

    /**
     * 获取所有的尺码列表（用以用户完善尺码的时候的展示）
     * @return \think\response\Json
     */
    public function selectSizes()
    {
        //,205,210,215,220,225
        $data = [
            100,110,120,130,140,150,160
            ,165,170,175,180,185,190,200
        ];
        return json(['status'=>200,'msg'=>$data]);
    }
    /**
     * 修改资料
     *
     */
    public function editStuInfo(){
        extract(input());
        $today = date('Y-m-d H:i:s');
        if(empty($uson_username)){
            return json(['status'=>1,'msg'=>'名字不能为空']);
        }
        if(!preg_match("/^1[123456789]\d{9}$/", $uson_parent_phone)){
            return json(['status'=>1,'msg'=>'请填写正确的手机号码']);
        }
//        if($uson_idcard){
//            $hkcard = Db::table('up_u_user_hkphone')->column('card');
//            if(!in_array($uson_idcard,$hkcard)) {
//                if($this->is_idcard($uson_idcard)){
//                    $age = date('Y') - substr($uson_idcard, 6, 4) - (date('md') >= substr($uson_idcard, 10, 4) ? 0 : 1);
//                    if($age < 5 || $age > 20){
//                        return json(['status'=>1,'msg'=>'年龄太大，请核实学生身份证号']);
//                    }
//                    $sexint = (int) substr($uson_idcard, 16, 1);
//                    $sexint = $sexint % 2 === 0 ? '2' : '1';
//                    if($sexint != $user_gender){
//                        return json(['status'=>1,'msg'=>'您选择的性别与身份证号性别不一致']);
//                    }
//                }else{
//                    return json(['status'=>1,'msg'=>'请输入正确的身份证号']);
//                }
//            }
//        }

//        if(!$uson_sheng || !$uson_shi || !$uson_qu || !$uson_address){
//            return json(['status'=>1,'msg'=>'地址不能为空']);
//        }
        if (empty($uson_school)) {
            return json(['status' => 1, 'msg' => '学校不能为空']);
        }
        if (empty($uson_year)) {
            return json(['status' => 1, 'msg' => '入学年份不能为空']);
        }
        if (empty($uson_grade)) {
            return json(['status' => 1, 'msg' => '年级不能为空']);
        }
//        $changeSchool = Db::table('up_u_user_son')->where('uson_id',$uson_id)->value('uson_school');
//        if($user_id != 1){
//            if($changeSchool != $uson_school){
//                return json(['status' => 1, 'msg' => '不能更改学校，请联系客服更改！']);
//            }
//        }
        if (!isset($uson_height)) $uson_height = '';
        if (!isset($uson_weight)) $uson_weight = '';
        //////---------------------------------------------------------------------
        $right = $this->gradeRight($uson_school,$uson_grade,$uson_year);
        if($right['status'] != 200){
            return json($right);
        }
        //////---------------------------------------------------------------------
        /// ----------------学生不能修改如果购物车有-------------
        $carHave = Db::table('up_self_car')
            ->where('car_user_son_id',$uson_id)
            ->where('car_type',2)
            ->find();
        if($carHave) return json(['status' => 1, 'msg' => '此学生购物车有未支付的校服，请清空或者支付~']);
        //-----------------学生不能修改如果购物车有-end----------
        $gradename = Db::table('up_school_grade')
            ->where('grade_id',$uson_grade)
            ->value('grade_name');
        $data = [
            'uson_user_id' => $user_id,
            'uson_username' => $uson_username,
//            'uson_idcard' => $uson_idcard,
            'uson_parent_phone' => $uson_parent_phone,
            'user_gender' => $user_gender,
            'uson_year' => $uson_year,
            'uson_school' => $uson_school,
            'uson_grade_id' => $uson_grade,
            'uson_grade' => $gradename,
            'uson_class' => $uson_class,
            'uson_size' => $uson_size,
//            'uson_sheng' => $uson_sheng,
//            'uson_shi' => $uson_shi,
//            'uson_qu' => $uson_qu,
//            'uson_address' => $uson_address,
            'uson_height' => $uson_height,
            'uson_weight' => $uson_weight,
            'uson_time' => $today,
            'uson_update_time' => $today
        ];
//        $have = Db::table('up_u_user_son')
//            ->where('uson_idcard',$uson_idcard)
//            ->where('uson_status','<>',3)
//            ->where('uson_id','<>',$uson_id)
//            ->find();
//        if($have){
//            return json(['status'=>0,'msg'=>'已经有此身份证号了']);
//        }else{
        Db::startTrans();
        try{
            if(isset($sun_num) && $sun_num){
                $haveNum = Db::table('up_school_number')->where('sn_number',$sun_num)->find();
                if(!$haveNum) return json(['status' => 1, 'msg' => '学号填写错误！']);
                if($haveNum['sn_status'] == 1){
                    Db::table('up_school_number')->where('sn_number',$sun_num)->update([
                        'sn_uson_id' => $uson_id,
                        'sn_status' => 2,
                        'sn_bindtime' => $today
                    ]);
                };
                //
                $data['uson_num'] = $sun_num;
            }
            Db::table('up_u_user_son')->where('uson_id',$uson_id)->update($data);
            Db::commit();
            return json(['status'=>200,'msg'=>'修改成功']);
        }catch(\Exception $e){
            Db::rollback();
            return json(['status'=>0,'msg'=>'操作失败，请刷新重试']);;
        }
    }
    /**
     * 商品列表
     * page
     *
     */
    public function getGoods(){
        extract(input());
        $can = $this->getSonByUser($user_id);
        if($can['status'] != 200){
            return json($can);
        }
        $sondata = $can['msg'];
        //校服不能冻结
        $where = [
            'good_status' => 1,
        ];
        if(isset($nowyear) && $nowyear){
            $sondata['uson_year'] = $nowyear;
        }
        $codes_years = $this->getStudentGoods($sondata['uson_school'],$sondata['uson_year'],$sondata['user_gender'],'','',1);
        $data = [];
        if($codes_years){
            $codes = $codes_years['codes'];
            $where['good_coding'] = ['in',$codes];
            $where['good_q'] = 1; //3、不展示Q版的
            $where['good_type'] = ['in','冬服,夏服,礼服,秋服,西服,配饰,军训服']; //3、不展示特殊类型的
            $where['good_pinming'] = ['not in','军训皮带,围巾,帽子,手拎包,背包,袜子,鞋套,鞋子']; //3、不展示特殊类型的；腰带又要卖了
            $field = 'good_id,good_name,good_price,good_thumb,school_name,school_id,good_year';
            $field = 'good_id,good_name,good_price,good_thumb,good_year,good_coding';
            $data = Db::table('up_goods')->alias('g')
//            ->join('up_school s','g.good_school=s.school_id','LEFT')
                ->where($where)
//            ->where('good_stock','>',0)
                ->field($field)
                ->order('good_year DESC')
                ->page ($page,12)
                ->select();
            if($data){
                foreach ($data as $k => $v){
                    if(empty($v['good_thumb'])){
                        $img = Db::table('up_z_new_old_img')->where('new',$v['good_coding'])->value('img');
                        if($img){
                            $data[$k]['good_thumb'] = $img;
                            $data[$k]['good_image'] = $img;
                            Db::table('up_goods')->where('good_id',$v['good_id'])->update([
                                'good_thumb' => $img,
                                'good_image' => $img
                            ]);
                        }
                    }
                    //
                    $data[$k]['good_price'] = getGoodsRealPrice($v['good_coding'],$sondata['uson_year'],$sondata);
                }
            }
            if(empty($codes_years['years'])){
                $codes_years['years'] = [];
            }
        }else{
            $codes_years['years'] = [];
        }


        return json(['status' => 200, 'msg' => $data, 'years' => $codes_years['years'], 'nowyear' => $sondata['uson_year']]);
    }

    /**
     * 商品详情
     */
    public function getGoodDetail()
    {
        extract(input());
        $can = $this->getSonByUser($user_id);
        if($can['status'] != 200){
            return json($can);
        }
        $sondata = $can['msg'];

        Db::table('up_goods')->where('good_id',$good_id)->setInc('good_click');
        $good = Db::table('up_goods')->alias('g')
            ->join('up_school s','g.good_school=s.school_id','LEFT')
            ->where('good_id',$good_id)
            ->find();
        if(isset($nowyear) && $nowyear){
            $sondata['uson_year'] = $nowyear;
        }
        $good['good_price'] = getGoodsRealPrice($good['good_coding'],$sondata['uson_year'],$sondata);
        if($good['good_status'] != 1){ //非上架不展示
            return json(['status'=>0,'msg'=>'此商品已下架']);
        }
        if($good['good_image']){
            if($good['good_name'] == '毛衣' || $good['good_name'] == '毛背心') $good['good_image'] = 'http://qiniu.panson.com/5090c7e403975ba3b070ca2cac1ed1ad.jpg,' . $good['good_image'];
            $good['good_image'] = explode(',',$good['good_image']);
        }else{
            $good['good_image'] = [];
            if($good['good_name'] == '毛衣' || $good['good_name'] == '毛背心') $good['good_image'] = ['http://qiniu.panson.com/5090c7e403975ba3b070ca2cac1ed1ad.jpg'];
        }
        //是否收藏
        $good['like'] = 0;
        $like = Db::table('up_like_goods')
            ->where('l_user_id',$user_id)
            ->where('l_good_id',$good_id)
            ->where('l_type',2)
            ->find();
        if($like){
            $good['like'] = 1;
        }
        //一条评价
        $comment = Db::table('up_goods_comment')->alias('gc')
            ->join('up_u_user u','gc.comment_user_id=u.user_id','LEFT')
            ->where('comment_good_id',$good_id)
            ->order('comment_time desc')
            ->field('gc.*,user_username,user_image,user_phone')
            ->find();
        if(!$comment){
            $comment = [];
        }else{
            if($comment['comment_image']){
                $comment['comment_image'] = explode(',',$comment['comment_image']);
            }
        }
        //获取尺寸
        //年份正好前面判断过了
        $sizes = $this->getInSizeForGood($good_id,'',$sondata);
        if($good['good_name'] == '毛衣' || $good['good_name'] == '毛背心') $good['good_content'] = '<p style="text-align: center;"><img src="http://qiniu.panson.com/20b5b2c60edc6ceee8d243ffc8bef62b.jpg"></p>' . $good['good_content'];
        return json(['status'=>200,'msg'=>$good,'comment'=>$comment,'sizes'=>$sizes,'default_size'=>$sondata['uson_size']]);
    }
    /**
     * 获取商品评价
     */
    public function getGoodComment()
    {
        extract(input());
        //一条评价
        $comment = Db::table('up_goods_comment')->alias('gc')
            ->join('up_u_user u','gc.comment_user_id=u.user_id','LEFT')
            ->where('comment_good_id',$good_id)
            ->order('comment_time desc')
            ->page($page,15)
            ->field('gc.*,user_username,user_image,user_phone')
            ->select();
        foreach ($comment as $k=>$v){
            if($v['comment_image']){
                $comment[$k]['comment_image'] = explode(',',$v['comment_image']);
            }
        }

        return json(['status'=>200,'msg'=>$comment]);
    }

    /**
     * 喜欢或者不喜欢商品
     */
    public function likeGoodsOrNot()
    {
        extract(input());
        return json(['status'=>0,'msg'=>'增补的校服不允许收藏哦~']);
        $have = Db::table('up_like_goods')
            ->where('l_type',2)
            ->where('l_good_id',$good_id)
            ->where('l_user_id',$user_id)
            ->find();
        if($have){
            $res = Db::table('up_like_goods')
                ->where('l_type',2)
                ->where('l_good_id',$good_id)
                ->where('l_user_id',$user_id)
                ->delete();

        }else{
            $res = Db::table('up_like_goods')->insert([
                'l_type'=>2,
                'l_good_id'=>$good_id,
                'l_user_id'=>$user_id,
                'l_time'=>date('Y-m-d H:i:s')
            ]);
        }
        if($res){
            return json(['status'=>200,'msg'=>'操作成功']);
        }else{
            return json(['status'=>0,'msg'=>'操作失败，请刷新重试']);
        }
    }
}